package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/14 23:02
 * @version  V1.0
 * @description:
 *
 */
func main() {

	var intArr [5]int = [...]int{1, 22, 33, 66, 99}

	//细节
	//[0:5]
	var slice02 = intArr[:5]
	fmt.Println(slice02)

	//[0:len(intArr)]
	var slice03 = intArr[0:]
	fmt.Println(slice03)

	//[0:len(intArr)]
	var slice04 = intArr[:]
	fmt.Println(slice04)

	//切片可以继续切片
	slice05 := slice02[0:5]
	fmt.Println("slice05=", slice05)
	slice05[0] = 100
	slice05[1] = 200
	slice05[2] = 300 //切片无论切多少次, 最终都指向同一个物理空间

	//表示slice引用数组intArr[i], i属于[1,3)
	slice := intArr[1:3]
	//intArr= [1 22 33 66 99]
	//show slice ele= [22 33]
	//slice ele nums= 2
	//slice cap= 4
	fmt.Println("intArr=", intArr)
	fmt.Println("show slice ele=", slice)
	fmt.Println("slice ele nums=", len(slice))
	fmt.Println("slice cap=", cap(slice)) //动态可变

	//way2
	var slice01 []float64 = make([]float64, 5, 10)
	//[0 0 0 0 0]
	fmt.Println(slice01)
	slice01[0] = 10
	slice01[1] = 10
	slice01[3] = 10

	fmt.Println(slice01)      //[10 10 0 10 0]
	fmt.Println(len(slice01)) //5
	fmt.Println(cap(slice01)) //10

	//way3
	var strSlice []string = []string{"tom", "jack", "marry"}
	fmt.Println(strSlice)      //[tom jack marry]
	fmt.Println(len(strSlice)) //3
	fmt.Println(cap(strSlice)) //3

}
